package com.hualan.service.impl;

import com.hualan.bean.PageResult;
import com.hualan.bean.PanghuShop;
import com.hualan.dao.ShopDao;
import com.hualan.dao.impl.ShopDaoImpl;
import com.hualan.service.ShopServiceDao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShopServiceDaoImpl implements ShopServiceDao {
    private ShopDao shopDao = new ShopDaoImpl();

    //查询shop全部信息
    public Map<String, Object> selectPage(String keyWord, String phone, String startTime, String endTime, Integer pageNum, Integer pageSize) {
        //调用dao层
        List<PanghuShop> list = shopDao.selectPage(keyWord, phone, startTime, endTime, pageNum, pageSize);
        Long count = shopDao.selectShopCount();
        Map<String, Object> map = new HashMap<>();
        PageResult<PanghuShop> data = new PageResult<>();
        data.setList(list);
        data.setTotal(Math.toIntExact(count));
        map.put("data", data);
        return map;
    }

    //增加shop
    @Override
    public Map<String, Object> addShop(String shopAddress, String shopDescribe, String shopImage, String shopLatitude, String shopLongitude, String shopName, String shopPhone) {
        int row = shopDao.addShop(shopAddress, shopDescribe, shopImage, shopLatitude, shopLongitude, shopName, shopPhone);
        Map<String, Object> map = new HashMap<>();
        if (row > 0) {
            map.put("code", 200);
        } else {
            map.put("code", 300);
        }
        return map;
    }

    //修改shop
    @Override
    public Map<String, Object> update(String addTime, String shopAddress, String shopCity, String shopDescribe, String shopDistrict, String shopImage, String shopLatitude, String shopLongitude, String shopName, String shopPhone, String shopProvince, String shopId) {
        int update = shopDao.update(addTime, shopAddress, shopCity, shopDescribe, shopDistrict, shopImage, shopLatitude, shopLongitude, shopName, shopPhone, shopProvince, shopId);
        Map<String, Object> map = new HashMap<>();
        if (update > 0) {
            map.put("code", 200);
        } else {
            map.put("code", 300);
        }
        return map;
    }
}
